package ooday03;

public class RefArrayDemo {

    static void show(Animal[] animals) {
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].eat();
        }
    }

    public static void main(String[] args) {
        Dog[] dogs = new Dog[3];//默认值为null
        dogs[0] = new Dog("大黄", 2, "黄");
        dogs[1] = new Dog("小白", 1, "白");
        dogs[2] = new Dog("小黑", 5, "黑");
        System.out.println(dogs[0].name);
        dogs[1].age = 4;
        dogs[2].swim();
        for (int i = 0; i < dogs.length; i++) {
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }

        Chick[] chicks = new Chick[2];//默认值为null
        chicks[0] = new Chick("鸡先锋", 2, "棕");
        chicks[1] = new Chick("先别鸡", 3, "黄");
        for (int i = 0; i < chicks.length; i++) {
            System.out.println(chicks[i].name);
            chicks[i].layEggs();
        }

        Fish[] fish = new Fish[4];//默认值为null
        fish[0] = new Fish("红泡泡", 9, "红");
        fish[1] = new Fish("绿泡泡", 8, "绿");
        fish[2] = new Fish("黄泡泡", 5, "黄");
        fish[3] = new Fish("蓝泡泡", 6, "蓝");
        for (int i = 0; i < fish.length; i++) {
            System.out.println(fish[i].color);
            fish[i].swim();
        }

        System.out.println("-----------------------------");
        //show方法设置为静态static 或 RefArrayDemo refArrayDemo = new RefArrayDemo(); 通过对象调用
        show(dogs);
        show(chicks);
        show(fish);


    }
}
